package com.ruoyi.app.controller.business.audit;

import com.ruoyi.business.base.PageParam;
import com.ruoyi.business.order.domain.JbRefund;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.business.order.factory.JbRefundFactory;
import com.ruoyi.web.controller.business.order.vo.JbRefundVO;
import com.ruoyi.web.core.JoController;
import com.ruoyi.web.core.JoR;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * APP 退款 Controller
 *
 * @author Jyl
 */
@RestController
@RequestMapping("/app/refund")
public class AppRefundController extends JoController
{

    private static final Logger log = LoggerFactory.getLogger(AppRefundController.class);

    @Autowired
    private JbRefundFactory jbRefundFactory;

    @ApiOperation("查询退款列表")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbRefund jbRefund)
    {
        return JoR.rows(jbRefundFactory.list(page, jbRefund));
    }

    @ApiOperation("新增退款")
    @Log(title = "退款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbRefundVO jbRefundVO)
    {
        if (jbRefundVO.getCommondityList().isEmpty())
        {
            return error("商品不正确");
        }
        if (!jbRefundFactory.add(jbRefundVO))
        {
            return AjaxResult.error("数据异常");
        }

        return AjaxResult.success();
    }

    @ApiOperation("修改退款")
    @Log(title = "退款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbRefundVO jbRefundVO)
    {
        if (jbRefundVO.getCommondityList().isEmpty())
        {
            return error("商品不正确");
        }
        if (!jbRefundFactory.edit(jbRefundVO))
        {
            return AjaxResult.error("数据异常");
        }
        return AjaxResult.success();
    }

    @ApiOperation("获取退款详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jbRefundFactory.getInfo(id));
    }

    @ApiOperation("删除退款")
    @Log(title = "退款", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jbRefundFactory.remove(ids));
    }
}
